//
//  MyContractTimeTableViewCell.m
//  PropertyManager
//
//  Created by TNG on 2018/7/18.
//  Copyright © 2018年 Tng. All rights reserved.
//

#import "MyContractTimeTableViewCell.h"

@implementation MyContractTimeTableViewCell

- (void)awakeFromNib {
    [super awakeFromNib];
    // Initialization code
}

-(instancetype) initWithStyle:(UITableViewCellStyle)style reuseIdentifier:(NSString *)reuseIdentifier
{
    if (self = [super initWithStyle:style reuseIdentifier:reuseIdentifier]) {
        [self creatUI];
    }
    return self;
}

-(void)creatUI{
    [self.contentView addSubview:self.titleLabel];
    [self.contentView addSubview:self.timeLabel];
}

-(UILabel *)titleLabel
{
    if (_titleLabel == nil) {
        _titleLabel = [[UILabel alloc] init];
        _titleLabel.font = font(12);
        _titleLabel.textColor = SFM51;
        _titleLabel.textAlignment = NSTextAlignmentLeft;
    }
    return _titleLabel;
}

-(UILabel *)timeLabel
{
    if (_timeLabel == nil) {
        _timeLabel = [[UILabel alloc] init];
        _timeLabel.font = font(14);
        _timeLabel.textAlignment = NSTextAlignmentCenter;
    }
    return _timeLabel;
}

-(void)send
{
    self.titleLabel.text = @"合同号：cc-2345";
    
    NSString * time = @"租期剩余：3天";
    CGFloat width = [time widthWithFont:font(14) constrainedToHeight:26];
    
    self.titleLabel.frame = CGRectMake(20, 10, WIDTH - width - 76, 26);
    
    self.timeLabel.frame = CGRectMake(WIDTH - width - 46, 10, width + 26, 26);
    self.timeLabel.layer.cornerRadius = 13;
    self.timeLabel.clipsToBounds = YES;
    self.timeLabel.text = time;
    
    if (1) {
        //正常
        self.timeLabel.textColor = SFMColor(39, 215, 21);
        self.timeLabel.backgroundColor = SFMColor(232, 251, 232);
    }else if(2)
    {
        //快过期的
//        self.timeLabel.textColor = SFMColor(235, 16.59, 21.79);
//        self.timeLabel.backgroundColor = SFMColor(255, 230, 231);
    }else
    {
        //已过期的
//        self.timeLabel.textColor = SFMColor(221, 221, 221);
//        self.timeLabel.backgroundColor = SFMColor(245, 245, 245);
    }
}

-(void)sendMyContractModel:(MyContractModel *)model
{
    self.titleLabel.text = [NSString stringWithFormat:@"合同号：%@",model.pactnum];
    NSDateFormatter *dateFormatter = [[NSDateFormatter alloc] init];
    [dateFormatter setDateFormat:@"yyyy-MM-dd"];
    NSInteger day = (int)[NSString getDaysFrom:[dateFormatter dateFromString:[NSString currentTimeAndFormat:@"yyyy-MM-dd"]] To:[dateFormatter dateFromString:model.pactenddate]];
    NSString * time;
    if (day<0) {
        time = @"已过期";
        self.timeLabel.textColor = SFMColor(221, 221, 221);
        self.timeLabel.backgroundColor = SFMColor(245, 245, 245);
    }else
    {
        time =[NSString stringWithFormat:@"租期剩余：%d",(int)day];
        if (day>=60) {
            //正常
            self.timeLabel.textColor = SFMColor(39, 215, 21);
            self.timeLabel.backgroundColor = SFMColor(232, 251, 232);
        }else
        {
            //快过期的
            self.timeLabel.textColor = SFMColor(235, 16.59, 21.79);
            self.timeLabel.backgroundColor = SFMColor(255, 230, 231);
        }
    }
    CGFloat width = [time widthWithFont:font(14) constrainedToHeight:26];
    
    self.titleLabel.frame = CGRectMake(20, 10, WIDTH - width - 76, 26);
    
    self.timeLabel.frame = CGRectMake(WIDTH - width - 46, 10, width + 26, 26);
    self.timeLabel.layer.cornerRadius = 13;
    self.timeLabel.clipsToBounds = YES;
    self.timeLabel.text = time;
}

- (void)setSelected:(BOOL)selected animated:(BOOL)animated {
    [super setSelected:selected animated:animated];

    // Configure the view for the selected state
}

@end
